import pathlib
from ..BaseCore.Selenium抽象类 import WebDriver,WebElement,Service,Options,By
from ..BaseCore.Selenium抽象类 import abstractmethod
from ..OnlineShopAbstraction.Selenium平台抖店抽象类 import DouDian
from ..OnlineShopAbstraction.Selenium平台拼多多抽象类 import PinDuoDuo
from ..OnlineShopAbstraction.Selenium平台淘宝抽象类 import TaoBao
import json,typing


class DouDian_TongZhuang(DouDian):
    def __init__(self):
        super().__init__()
    
    def FastStart(self,config="config.json"):
        self.log.info("任务开始!")

        self.browser.force_start_debug_browser()
        self.base.wait(1)
        self.LoadConfigFile(config_file=config).InitDriver()
        self.base.Goto_CurrentActivateUrl()

        try:
            self.OpenCreateProductPage()
        except:
            self.log.warning("打开发布页面失败!")

        try:
            self.SelectFirstCategory()
        except:
            self.log.warning("选择一级类目失败!")
            
        try:
            self.SelectSecondCategory()
        except:
            self.log.warning("选择二级类目失败!")
            
        try:
            self.SelectThirdCategory()
        except:
            self.log.warning("选择三级类目失败!")
            
        try:
            self.SelectfourthCategory()
        except:
            self.log.warning("选择四级类目失败!")

        try:
            self.FillProductTitle()
        except:
            self.log.warning("填写商品标题失败!")
        
        try:
            self.FillProductMainImage()
        except:
            self.log.warning("填写商品主图失败!")
        
        try:
            self.GotoParamSettingPage()
        except:
            self.log.warning("跳转到参数设置页面失败!")

        try:
            self.FillProductParams()
        except:
            self.log.warning("填写商品参数失败!")
        
        try:
            self.FillProductMaterial()
        except:
            self.log.warning("填写商品材质失败!")
        
        try:
            self.FillProductDetailImage()
        except:
            self.log.warning("填写商品详情图失败!")
        
        try:
            self.FillProductSku()
        except:
            self.log.warning("填写商品SKU失败!")
        
        try:
            self.FillProductSizes()
        except:
            self.log.warning("填写商品尺寸失败!")
        
        try:
            self.FillProductPrice()
        except:
            self.log.warning("填写商品价格失败!")
        
        try:
            self.FillProductInventory()
        except:
            self.log.warning("填写商品库存失败!")
        
        try:
            self.FillProductShopLabel()
        except:
            self.log.warning("填写商品商铺标签失败!")
        
        try:
            self.FillProductLogistics()
        except:
            self.log.warning("填写商品物流失败!")

        try:
            self.FillSizeCharts()
        except:
            self.log.warning("填写尺寸图表失败!")
        
        try:
            self.FillProductLogistics()
        except:
            self.log.warning("填写商品物流失败!")

        try:
            self.FindProductTitle()
        except:
            self.log.warning("商品主图标题识别失败!")

        self.driver.quit()
        self.log.info("驱动关闭!")
        self.log.info("任务完成!")

        while True:
            i = input("输入 q 或者 quit 回车结束!")
            if i == "q" or i == "quit":
                break